

//class中构造函数是this ， case class中构造函数是apply

case class Person(var name: String, var age: Int, sex: String) {

  override def toString: String = {
    name + "," + age + "," + sex
  }

}

object Person {

  //case class 中的辅助构造函数
  def apply(name: String): Person = new Person(name, 30, "帅哥")

  def apply(name: String, age: Int): Person = new Person(name, age, "猛男")

  def main(args: Array[String]): Unit = {
    println(Person("xiaohui")) //"xiaohui,30,帅哥"
    println(Person("xiaohui", 18).toString) //"xiaohui,18,猛男"
    println(Person("xiaohui", 20, "暖男").toString) //"xiaohui,20,暖男"
  }

}


